package object;

public class Test {
    public static void main(String[] args) {
//        try{
//            int[] arr = {1,2,3,4,5};
//            System.out.println(arr[100]);
//        } catch(RuntimeException e){
//            System.out.println("数组越界");
//        } finally{
//            System.out.println("异常解决");
//        }


//        double a = 10 / 0.0;
//        System.out.println(a);  //Infinity-->无穷大

//        int x = 10;
//        int y = 0;
//        System.out.println("抛出异常前");
//        System.out.println(devide(x,y));
//        System.out.println("抛出异常后");
//
//    }
//
//    public static int devide(int a,int b){
//        if(b == 0){
//            throw new ArithmeticException("不能用0作为除数");
//        }
//        return a / b;


        System.out.println("抛出异常前");
        try{
            fun2();
        } catch(ArithmeticException e){
            System.out.println("0不能做为除数");
            e.printStackTrace();
        } finally{
            System.out.println("抛出异常后");
        }
    }

    public static int devide(int a,int b){
        System.out.println("调用devide方法");
        return a / b;

    }
    public static void fun1(){
        //try{
            System.out.println("调用fun1方法");
            devide(10,0);
        //} catch(ArithmeticException e){
            //System.out.println("在fun1捕获异常");
            //e.printStackTrace();


    }
    public static void fun2(){
        System.out.println("调用fun2方法");
        fun1();
    }
}
